package com.qf.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * --- 缘分让我们相遇乱世以外 ---
 *
 * @author SJY
 * @date 2024/11/8
 * @desc
 */
@WebServlet("/show/resp")
public class Demo2Servlet extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 响应头不需要关
        // 响应状态码,路径不需要关
        // 只需要设置响应正文(主要内容)

        // 如果乱码,设置响应到浏览器的内容格式
        resp.setContentType("text/html;charset=utf-8");// 设置返回的html页面

        // 使用的是字符输出流
        PrintWriter out = resp.getWriter();
        out.write("这是响应的内容~");
        out.write("<html>");
        out.write("<head>");
        out.write("<title>演示响应</title>");
        out.write("</head>");
        out.write("<body>");
        out.write("<h1>这是响应的内容~</h1>");
        out.write("</body>");
        out.write("</html>");
    }
}